﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using BCMS.Settings;

namespace BCMS.Forms
{
    public partial class frmSystemConfiguration : Form
    {
        public frmSystemConfiguration()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.ConnectionStrings.ConnectionStrings.Remove("CNN");
                config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("CNN", string.Format("Server={0};User ID={1};Persist Security Info=True;Database={2};Password={3};Pooling=true;", txtServer.Text, txtUserName.Text, txtDBName.Text, txtPassword.Text)));
                config.Save(ConfigurationSaveMode.Modified);
                GlobalVars.ShowInfo("Cập nhật [THÀNH CÔNG]. Mở lại chương trình để thay đổi có hiệu lực.");
                this.Close();
            }
            catch (System.Exception ex)
            {
                GlobalVars.ShowError("Lỗi: " + ex.Message);
            }
        }

        private void frmSystemConfiguration_Load(object sender, EventArgs e)
        {

        }
    }
}
